package top.infopub.mgr.fia.web;


import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.infopub.enums.fia.IncomeBillTypeEnum;
import top.infopub.mgr.common.page.ParamPage;
import top.infopub.mgr.common.vo.RspVo;
import top.infopub.mgr.fia.domain.IncomeBillDomain;
import top.infopub.mgr.fia.service.IncomeBillService;
import top.infopub.mgr.fia.vo.IncomeBillVo;
import top.infopub.mgr.flow.web.GenericFlowController;
import top.infopub.model.fia.IncomeBill;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;


/**
 * 收款单登记表管理
 * @author wangw
 * @version 2020年1月14日
 * @see IncomeBillController
 * @since
 */
@Controller
@RequestMapping("/incomeBill")
public class IncomeBillController extends GenericFlowController {
    @Autowired
    private IncomeBillService incomeBillService;

    /**
     * 收款单登记表列表
     * @return
     */
    @RequestMapping("/list")
    public String list(HttpServletRequest request) {
        List<Map<String, String>> incomeBillType = IncomeBillTypeEnum.asList();
        request.setAttribute("incomeBillType",incomeBillType);
        return "fia/lay-incomeBill-list";
    }
    
    /**
     * 收款单登记表列表数据
     * @return
     */
    @RequestMapping("/queryDataByCondition")
    @ResponseBody
    public RspVo<IncomeBillDomain> queryDataByCondition(IncomeBillVo incomeBillVo, ParamPage paramPage) {
        Page<IncomeBillDomain> page = new Page<IncomeBillDomain>();
        page.setPageNum(paramPage.getPage());
        page.setPageSize(paramPage.getLimit());
        page = incomeBillService.selectPageByDomainWhere(page, incomeBillVo);
        return RspVo.getSuccessResponse(page.getTotal(), page.getResult());
    }

    /**
     * 根据id查询详情  > 注意：方法命名必须为：toDealOrDetail
     * @param id SGUID
     * @return
     * @see
     */
    @RequestMapping("/toDealOrDetail")
    public String toDealOrDetail(HttpServletRequest request, String id, String proCode) {
        IncomeBill incomeBill = incomeBillService.selectByPrimaryKey(id);
        // 当前审批关联业务表单表名
        String bizTableName = incomeBill.getBizTableName();
        // 当前审批关联业务表记录ID
        String bizSguid = incomeBill.getBizSguid();
        // 进行跳转
        return bizControllerUrl(bizTableName, bizSguid, incomeBill.getProCode());
    }
}
